<?php
/**
 * 检查设备管理菜单
 */

// MySQL连接配置
$host = '113.44.136.17';
$port = '3306';
$database = 'qiandao';
$username = 'qiandao';
$password = 'NGbks3HWx5PhSxDX';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 检查设备管理菜单 ===\n\n";
    
    // 查找打卡积分菜单
    $stmt = $pdo->query("SELECT id, title FROM system_menu WHERE title = '打卡积分' AND pid = 0");
    $parentMenu = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$parentMenu) {
        echo "❌ 未找到'打卡积分'一级菜单\n";
        exit(1);
    }
    
    echo "✓ 找到打卡积分菜单 (ID: {$parentMenu['id']})\n\n";
    
    // 查找设备管理相关菜单
    $stmt = $pdo->prepare("
        SELECT id, pid, title, node, status, sort 
        FROM system_menu 
        WHERE (title LIKE '%设备%' OR node LIKE 'checkin/device%') 
        ORDER BY pid, sort DESC, id ASC
    ");
    $stmt->execute();
    $deviceMenus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if (empty($deviceMenus)) {
        echo "❌ 没有找到设备管理相关菜单\n";
    } else {
        echo "设备管理菜单:\n";
        foreach ($deviceMenus as $menu) {
            $level = $menu['pid'] == $parentMenu['id'] ? '二级' : '三级';
            $status = $menu['status'] == 1 ? '启用' : '禁用';
            echo "  [{$level}] ID:{$menu['id']} PID:{$menu['pid']} {$menu['title']} (node:{$menu['node']}, 状态:{$status}, 排序:{$menu['sort']})\n";
        }
    }
    
    // 检查所有checkin相关菜单
    echo "\n所有checkin模块菜单:\n";
    $stmt = $pdo->query("
        SELECT id, pid, title, node, status, sort 
        FROM system_menu 
        WHERE node LIKE 'checkin/%' 
        ORDER BY pid, sort DESC, id ASC
    ");
    $checkinMenus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    foreach ($checkinMenus as $menu) {
        $status = $menu['status'] == 1 ? '启用' : '禁用';
        echo "  ID:{$menu['id']} PID:{$menu['pid']} {$menu['title']} (node:{$menu['node']}, 状态:{$status})\n";
    }
    
    echo "\n=== 检查完成 ===\n";
    
} catch (PDOException $e) {
    echo "❌ 数据库错误: " . $e->getMessage() . "\n";
}
?>
